﻿//---*Authenticity Seal
/*			                                _ .--.
					                       ( `    )
									     .-'      `--,
			                  _..----.. (             )`-.
			                .'_|` _|` _|(  .__,           )
						   /_|  _|  _|  _(        (_,  .-'
			              ;|  _|  _|  _|  '-'__,--'`--'
			              | _|  _|  _|  _| |
			          _   ||  _|  _|  _|  _|
			        _( `--.\_|  _|  _|  _|/
			      .-'       )--,|  _|  _|.`
				(__, (_      ) )_|  _| /
			      `-.__.\ _,--'\|__|__/
			                    ;____;
			                     \  /
								  OO
			                     |""|
			                     '=='
			                     
           			 Autor: Federico Angel Donnet
*/
//---*Authenticity Seal
//---*Este Script se encarga de etiquetar de alguna forma este Emisor de Particulas.
//---*Ademas se encarga de informar que tipo de emitter debe crearce y cuantos (para el pool de EmiterFactoryController)
using UnityEngine;
using System.Collections;
//---*Para usar lista!
using System.Collections.Generic;

public class EmitterPackage : MonoBehaviour 
{

	//----------------//
	//---*Atributos:
	//----------------//
	//---*Etiqueta/Nombre del Package para que sea mas facil la busqueda:
	public	string				EmitterName				=	"No Name";
	//---*Molde o Prefab del emitter:
	public	GameObject			Emitter					=	null;
	//---*Cantidad que vamos a crear de este emitter para el pool de "EmitterFactoryControllerScript" (por defecto 3):
	public	int					nEmitters				=	3;
	//---*Lista que almacena las instancias de Emitter:
	private	List<GameObject> 	members					=	null;
	//----------------//
	//---*Metodos:
	//----------------//
	// Use this for initialization
	void Start ()
	{
		//---*Crea el pool de Emitter:
		if(this.Emitter != null)
		{
			this.members = new List<GameObject>();
			for(int n=0;n<this.nEmitters;n++)
			{
				this.members.Add(Instantiate(this.Emitter) as GameObject);
				this.members[n].gameObject.transform.position	=	Vector3.zero;
				this.members[n].gameObject.transform.rotation	=	new Quaternion (0.0f,0.0f,0.0f,0.0f);
				this.members[n].gameObject.transform.parent 	=	this.gameObject.transform;
				this.members[n].gameObject.SetActive(false);
			}

		}
	}

	public	void Play(Vector3 pos)
	{
		//---*Recorremos la lista "members" y buscamos un emitter que este disponible:
		for (int n=0;n<this.members.Count;n++)
		{
			if(!this.members[n].activeInHierarchy)
			{
				this.members[n].gameObject.GetComponent<EmitterActive>().Play(pos);
				//---*Cortamos la busqueda:
				break;
			}
		}
	}

}
